/*Copyright © 2008 Cassarin-Grand Arthur (Zoloom)

This file is part of PlayOnLinux Script Creator.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */

#include "files.h"
#include "gui/Fenfunctions.h"
#include "gui/Fenp.h"

using namespace std;

int Fenp::openFile(QString fileName)
{
	if (fileName == "")
	{
		fileName = QFileDialog::getOpenFileName(this, "Open a file", QString(), "");
		
		if (fileName != "")
		{
			QFile fileOpened(fileName);
		 	fileOpened.open(QIODevice::ReadOnly | QIODevice::Text);

			QString strBuffer;
			QTextStream streamFileOpened(&fileOpened);
					
			while(!streamFileOpened.atEnd())
				strBuffer = strBuffer + streamFileOpened.readLine() + '\n';
	
			showFile(fileName, strBuffer);
		}
		
		else{return 1;}
	}
	
	if (fileName != "")
	{	
		QFile fileOpened(fileName);
		 	fileOpened.open(QIODevice::ReadOnly | QIODevice::Text);

		QString strBuffer;
		QTextStream streamFileOpened(&fileOpened);
		
		 while(!streamFileOpened.atEnd())
			strBuffer = strBuffer + streamFileOpened.readLine() + '\n';
	
		showFile(fileName, strBuffer);
	}
	
	return 0;
}

int Fenp::saveFile(QString fileName)
{
	return 0;
}

int Fenp::saveAsFile(QString fileName, QString fileDestination)
{
	return 0;
}
